<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>套餐添加</title>
    <link rel="stylesheet" href="/scriptZIP/layui.min.css">
    <link rel="stylesheet" href="css/common2.css">
    <link rel="stylesheet" href="css/layui.css" />
    <link rel="stylesheet" href="/scriptZIP/vue-select.min.css">
    <style>
        .layui-row {
            margin-top: 50px;
        }

        .required::before {
            content: "*";
            color: red;
            font-size: 15px;
            margin-right: 5px;
        }
    </style>
</head>

<body>

    <form class="layui-form" id="vue-root">
        <div class="layui-row">
            <div class="layui-col-md6 layui-col-md-offset3">
                <div class="layui-form-item">
                    <label class="layui-form-label">交费年限</label>
                    <div class="layui-input-block">
                        <!-- <select name="mealName" class="layui-input publicId" v-model="item.mealName">
                            <option :value="undefined" disabled="disabled">请选择年限</option>
                            <option v-for="item in yearList" v-text="item" :key="item" :value="item"></option>
                        </select> -->
                        <input name="mealName" type="number" autocomplete="off" placeholder="请输入年限,例：1" class="layui-input telname"
                            v-model="item.mealName">
                        <div class="checkout_state" v-text="err('mealName')"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">交费金额</label>
                    <div class="layui-input-block">
                        <input name="packageAmount" type="number" autocomplete="off" placeholder="请输入交费金额" class="layui-input telname"
                            v-model="item.packageAmount">
                        <div class="checkout_state" v-text="err('packageAmount')"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <div class="offer" @click="submit11">立即提交</div>
                        <div class="return" onclick="history.back()">取消</div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <script src="/scriptZIP/qs.min.js"></script>
    <script src="/scriptZIP/vue.min.js"></script>


    <script src="/scriptZIP/axios.min.js"></script>
    <script src="/scriptZIP/vue-select.min.js"></script>
    <script src="/scriptZIP/dayjs.min.js"></script>

    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/item.js"></script>
    <script src="/js/area.js"></script>

    <script>
        Vue.component('v-select', VueSelect.VueSelect);
        var app = new Vue(mergeArea(merge({
            data: {
                // yearList: ["一年", "两年", "三年", "四年", "五年", "六年", "七年", "八年", "九年", "十年", "十一年", "十二年"],
                item: {},
                url: '/pc/menu/add',
                img: '/image/upload.png'
            },
            created: function () {
                var id = params().id//拿到跳转过来传的参数
                if (id) {
                    axios.post('/pc/menu/getMenu').then(function (res) {
                        var arr =Array.from(res.data.setMenus);
                        var arr2 = arr.filter(it => {
                            return it.id == id
                        });
                        this.item=arr2[0];
                    }.bind(this));
                }

            },
            methods: {
                submit11: function () {
                    if(!this.item.mealName || !this.item.packageAmount ) {alert('请输入完整信息！');this.item.packageAmount='';this.item.mealName=''; return };
                    if(this.item.mealName<0 || this.item.packageAmount<0){alert('不能小于0');this.item.packageAmount='';this.item.mealName=''; return };
                    if(this.item.mealName==0 || this.item.packageAmount==0){alert('不能为0');this.item.packageAmount='';this.item.mealName=''; return };
                    var success = function () {
                        alert(locale == 'en' ? 'succeed' : '成功');
                        history.back();
                    };
                    this.item.mealName =Math.round(this.item.mealName)
                    this.$validator.validate().then(function (result) {
                        if (result) {
                            if (this.item.id) {
                                axios.put('/pc/menu', this.item).then(success);
                            } else {
                                axios.post(this.url, this.item).then(success);
                            }
                        } else {
                            alert(locale == 'en' ? 'Please enter the complete information' : '请输入完整信息！');
                        }
                    }.bind(this));
                },
            }
        })));

    </script>
</body>

</html>